package com.jiandaoshou.adapter;

import android.content.Context;
import android.support.v7.widget.AppCompatCheckBox;

import com.jiandaoshou.R;
import com.jiandaoshou.entry.CardInfo;
import com.jiandaoshou.utils.LogUtil;

import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

/**
 * Created by Administrator on 2016/9/29.
 */

public class MyYinHangAdapter extends QuickAdapter<MyYinHangAdapter.Choice> {

    public MyYinHangAdapter(Context context) {
        super(context, R.layout.item_choiceyinhangka);
    }


    private void setDefault(){
        for (int i = 0; i < data.size(); i++) {
            Choice bank = data.get(i);
            bank.isSelect = false;
        }
    }

    @Override
    protected void convert(BaseAdapterHelper helper, final Choice bank) {
        LogUtil.e("bank......."+bank.isSelect);
        helper.setText(R.id.tv_choiceyinhangname, bank.bank.getStrBankName());
        String zhanghao=bank.bank.getStrCardNumber();
        String str="";
        if(zhanghao.length() > 4)
            str="************"+zhanghao.substring(zhanghao.length()-4,zhanghao.length());
        else{
            str="************"+zhanghao;
        }

        helper.setText(R.id.tvZhuRen,String.format("%s%s",bank.bank.getStrCardHolderName(),str));

        AppCompatCheckBox checkBox = helper.getView(R.id.checkbox_yinhangka);
        checkBox.setOnClickListener(v -> {
            setDefault();
            bank.isSelect = !bank.isSelect;
            notifyDataSetChanged();
        });
        checkBox.setChecked(bank.isSelect);
    }

    public void update(Choice bank,int pos){
        getList().get(pos).isSelect=true;
        notifyDataSetChanged();
    }

    public static class Choice{
        public CardInfo bank;
        public boolean isSelect = false;
    }

}
